package com.cloudfactory.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cloudfactory.po.News;
import com.cloudfactory.service.NewsService;

@Controller
@RequestMapping(value = "/")
public class NewsController {

	@Autowired
	private NewsService newsService;

	@RequestMapping(value = "/news")
	public String news(Model model) {
		List<News> newsList = newsService.selectAll();
		model.addAttribute("newsList", newsList);
		return "/news.jsp";
	}

	@RequestMapping(value = "/news-content")
	public String newsContent(Model model, @RequestParam("id") Long id) {
		News news = newsService.selectById(id);
		model.addAttribute("news", news);
		return "/news-content.jsp";
	}
}
